package com.app.utils;

import android.content.Context;
import android.text.TextUtils;

import com.core.lib.core.ApiClient;
import com.core.lib.core.AsyncRequest;
import com.core.lib.utils.main.AppManager;
import com.core.lib.utils.main.LogUtilBase;
import com.core.lib.utils.main.UtilityBase;

public class DspTongJi implements AsyncRequest {

	private static final boolean needDsp = false;
	
	public static final String REQUEST_FIRST_USE = "request_first_use";
	public static final String REQUEST_REGISTER_SUCCESS = "request_register_success";

	public void requestFirstUse(Context context) {
		
		if(needDsp)
		{
			String umengChannel = UtilityBase.getAppMetedata(context,
					"UMENG_CHANNEL");
			if (!TextUtils.isEmpty(umengChannel) && umengChannel.equals("dsp")) {
				try {
					String url = "http://dsp.svc.mobivans.com/track/app/install?imei="
							+ AppManager.getDeviceUniqueId(context);
					ApiClient.http_get(url, this, REQUEST_FIRST_USE);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}else{
				LogUtilBase.LogD(null, REQUEST_FIRST_USE+"_不是dsp渠道");
			}
		}
	}

	public void requestRegisterSuccess(Context context) {
		
		if(needDsp)
		{
			String umengChannel = UtilityBase.getAppMetedata(context,
					"UMENG_CHANNEL");
			if (!TextUtils.isEmpty(umengChannel) && umengChannel.equals("dsp")) {
				try {
					String url = "http://dsp.svc.mobivans.com/track/app/trans?imei="
							+ AppManager.getDeviceUniqueId(context);
					ApiClient.http_get(url, this, REQUEST_REGISTER_SUCCESS);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}else{
				LogUtilBase.LogD(null, REQUEST_REGISTER_SUCCESS+"_不是dsp渠道");
			}
		}
	}

	@Override
	public void RequestComplete(Object object, Object data) {
		if (object.equals(REQUEST_FIRST_USE)) {
			LogUtilBase.LogD(null, REQUEST_FIRST_USE + "_success");
		} else if (object.equals(REQUEST_REGISTER_SUCCESS)) {
			LogUtilBase.LogD(null, REQUEST_REGISTER_SUCCESS + "_success");
		}
	}

	@Override
	public void RequestError(Object object, int errorId, String errorMessage) {
		if (object.equals(REQUEST_FIRST_USE)) {
			LogUtilBase.LogD(null, REQUEST_FIRST_USE + "_fail");
		} else if (object.equals(REQUEST_REGISTER_SUCCESS)) {
			LogUtilBase.LogD(null, REQUEST_REGISTER_SUCCESS + "_fail");
		}
	}
}
